import {ParamMap, Router} from "@angular/router";
import {Injectable} from "@angular/core";

@Injectable({
  providedIn: 'root'
})
export class UrlService {
  private url: string = "/";
  private params?: ParamMap;


  reset(router: Router): void {
    this.url = router.url;
    this.params = router.parseUrl(router.url).queryParamMap;
  }

  equals(url: string): boolean {
    return this.url === url;
  }

  startWith(prefixUrl: string): boolean {
    return this.url.startsWith(prefixUrl);
  }

  matchs(fragmentUrl: string): boolean {
    return new RegExp(fragmentUrl).test(this.url);
  }

}
